<?PHP
// reservation.php - Manage booking asset or car.
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//
// Author: Ouedarbi Mohamed

$PLUGININFO['ticket']['version'] = 1.1;
$PLUGININFO['ticket']['description'] = 'Add incident - details incident - incidents MOD';
$PLUGININFO['ticket']['author'] = 'Ouedarbi Mohamed';
$PLUGININFO['ticket']['legal'] = 'GPL';
$PLUGININFO['ticket']['sitminversion'] = 3.60;
$PLUGININFO['ticket']['sitmaxversion'] = 3.69;

plugin_register('define_menu', 'menu_ticket');

function menu_ticket()
{
    global $hmenu, $CFGVAR, $CONFIG;

//unset($hmenu[30][10]);
$hmenu[0][30]['url'] = "{$CONFIG['application_webpath']}plugins/ticket/tickets.php?user=all&amp;queue=1&amp;type=support";
$hmenu[30][10]['url'] = "{$CONFIG['application_webpath']}plugins/ticket/ticket_add.php";
$hmenu[30][20]['url'] = "{$CONFIG['application_webpath']}plugins/ticket/tickets.php";
$hmenu[30][30]['url'] = "{$CONFIG['application_webpath']}plugins/ticket/tickets.php?user=all&amp;queue=1&amp;type=support";
$hmenu[30][50]['url'] = "{$CONFIG['application_webpath']}holding_queue.php";
ksort($hmenu[30], SORT_NUMERIC);
}
$dbTicket = "{$CONFIG['db_tableprefix']}ticket";

plugin_register('cfgvar', 'ticket_cfgvar');

function ticket_cfgvar()
{
    global $CFGTAB, $CFGCAT, $CFGVAR,$CATINTRO; 
    $CATINTRO['ticket'] = 'This text will appear at the top somewhere';
    $CFGTAB['plugins'] = array_merge((array)$CFGTAB['plugins'],  array('ticket'));
    $CFGCAT['ticket'] = array('ticket_assetid', 'ticket_contact');
   
   $CFGVAR['ticket_assetid']['title'] = 'Enable Hardware ID';
    $CFGVAR['ticket_assetid']['help'] = 'Set this to display text box , third part inventory required';
    $CFGVAR['ticket_assetid']['options'] = 'yes|no';
    $CFGVAR['ticket_assetid']['type'] = 'select';
	
	$CFGVAR['ticket_contact']['title'] = 'Enable Alternate contact text field';
    $CFGVAR['ticket_contact']['help'] = 'Set this to display text box linked to contact database Name firstname , active after typing first 3 letter ';
    $CFGVAR['ticket_contact']['options'] = 'yes|no';
    $CFGVAR['ticket_contact']['type'] = 'select';

}

plugin_register('config_save', 'ticket_save');

function ticket_save()
{
    global $CONFIG;
    $CONFIG['debug_mode'] = TRUE;
    $sql = "ALTER TABLE `sit_updates` CHANGE `sla` `sla` ENUM('opened','initialresponse','probdef','actionplan','solution','closed','planned')";
    $result=@mysql_query($sql);
// check if ticket table exists, if not, create it
    $sql2 = "SELECT * FROM {$CONFIG['db_tableprefix']}ticket";
    $result2=@mysql_query($sql2);
    if (!$result2)
    {
      $schema = "CREATE TABLE `sit_ticket` (
  `id` int(11) NOT NULL auto_increment,
  `incidentid` int(11) NOT NULL default '0',
  `alternate_contact` varchar(50) character set utf8 default NULL,
  `asset_id` varchar(50) character set utf8 default NULL,
  `site_location` int(11) NOT NULL default '0',
  `description` text character set utf8,
  `date_neededby` int(11) NOT NULL default '0',
  `assigned` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`)

    )";
    $result2 = mysql_query($schema);
    if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
    if (mysql_error())
    {
        echo "<p>tms_backup failed to install, please run the following SQL statement on the SiT database to create the required schema.</p>";
        echo "<pre>{$schema}</pre>";
        $res = FALSE;
    }
    else $res = TRUE;

    }
}

?>